<?php

/**
 * Created by PhpStorm.
 * User: Yieong
 * Date: 16/4/5
 * Time: 下午8:21
 */
class OperationController extends AdminBaseController {
	
	public function kick(){
		$this->setTitle('踢玩家下线');
		//$this->out['serverList'] = ServerService::getOptions();
		
		$osList = PubAuthSession::get('os');
		$this->out['osList']      = $osList;
		
		$this->out['serverList'] = ServerService::getOptions1();
	}
	
	public function doKick(){
		$this->setTitle('踢下线结果');
		$server = $this->R('server');
		$params = array(
				'kickall'   => $this->R('kick_all'),
				'kicktype'  => $this->R("kick_type"),
				'list'      => $this->R('data'),
				'reason'    => $this->R('reason')
		);
	
		$result = OperationService::doKick($server, $params);
		$url = PubFunc::buildUrl('/oss/?r=operation/kick');
	
		if($result['state']){
			$this->out['data'] = $result['data'];
			$this->out['desc'] = $result['desc'];
			$this->out['url'] = $url;
		}else{
			$this->showMessage($result['msg'], $url);
		}
	}
	
	
	public function banChat(){
		$this->setTitle('角色禁言');
		$this->out['banType']       = OperationService::banType();
		$this->out['channelType']   = OperationService::channelType();
		$this->out['serverList']    = ServerService::getOptions();
	}
	
	public function doBanChat(){
		$server = $this->R('server');
		$params = array(
				'actiontype'        => $this->R('status'),
				'channel'       => $this->R('ban_channel'),
				'list'          => $this->R('data'),
				'bandate'       => $this->R('ban_date'),
				'ban_forever'   => $this->R('ban_forever'),
				'reason'        => $this->R('reason')
		);
	
		$result = OperationService::doBanChat($server, $params);
	
		$url = PubFunc::buildUrl('/oss/?r=operation/banChat');
	
		if($result['state']){
			$this->showMessage((($params['status'] == 1) ? '禁言' : '解禁').'操作成功', $url);
		}else{
			$this->showMessage($result['msg'], $url);
		}
	}

    public function ban(){
        $this->setTitle('账号封禁');
        $this->out['banType']       = OperationService::banType();
        $this->out['serverList']    = ServerService::getOptions();

        $this->out['server']    = $this->R('server');
        $this->out['uid']       = $this->R('uid');
    }

    public function doBan(){
        $this->setTitle('封禁结果');
        $server = $this->R('server');
        $params = array(
            'bantype'       => $this->R('ban_type'),
            'list'          => $this->R('data'),
            'actiontype'        => $this->R('status'),
            'bandate'       => $this->R('ban_date'),
            'ban_forever'   => $this->R('ban_forever'),
            'reason'        => $this->R('reason')
        );

        $result = OperationService::doBan($server, $params);

        $url = PubFunc::buildUrl('/oss/?r=operation/ban');

        if($result['state']){
            $this->out['data'] = $result['data'];
            $this->out['desc'] = $result['desc'];
            $this->out['url'] = $url;
        }else{
            $this->showMessage($result['msg'], $url);
        }
    }

    

    

    public function deduct(){
        $this->setTitle('扣除玩家金币/道具');

        $this->out['itemList']  = ItemService::getItemType();
        $this->out['goldList']  = SendService::goldList();
        $this->out['itemUrl']   = PubFunc::buildUrl('/oss/?r=item/ajax');
    }

    public function doDeduct(){
        $params = array(
            'type'      => $this->R('type'),
            'role_id'   => $this->R('role_id'),
            'prop_id'   => $this->R('prop_id'),
            'prop_num'  => $this->R('prop_num'),
            'only_id'   => $this->R('only_id'),
            'gold_id'   => $this->R('gold_id'),
            'gold_num'  => $this->R('gold_num'),
            'reason'    => $this->R('reason')
        );

        $result = OperationService::doDeduct($params);

        $url = PubFunc::buildUrl('/oss/?r=operation/deduct');
        if($result['state']){
            $this->showMessage('扣除成功', $url);
        }else{
            $this->showMessage($result['msg'], $url);
        }
    }

    public function clear(){
        $this->setTitle('重置复活点');
        $this->out['serverList'] = ServerService::getOptions();
    }

    public function doClear(){
        $this->setTitle('重置结果');
        $server = $this->R('server');
        $params = array(
            'roleType'  => $this->R("clear_by"),
            'ClearType' => $this->R('clear_type'),
            'data'      => $this->R('data'),
        );

        $result = OperationService::doClear($server, $params);
        $url = PubFunc::buildUrl('/oss/?r=operation/clear');

        if($result['state']){
            $this->showMessage('操作成功', $url);
        }else{
            $this->showMessage($result['msg'], $url);
        }
    }
}